<?php
/**
 * 美食TAG管理 - 已入库的TAG删除掉，注意，只删除一个分类下的TAG
 *
 * @copyright dongping
 * @since 2012-03-24
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();



function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	
	cgi::both($g_cgival["tag"], "tag", "");
	$g_cgival["tag"] = string::un_script_code($g_cgival["tag"]);
	$g_cgival["tag"] = string::un_html($g_cgival["tag"]);

	
	
	// 分类
	cgi::both($g_cgival["tag_class"], "tag_class", "");
	$g_cgival["tag"] = string::un_script_code($g_cgival["tag"]);
	$g_cgival["tag"] = string::un_html($g_cgival["tag"]);
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	// $g_show = $g_cgival;
	
	
	$tag_class = $g_cgival["tag_class"];
	$tag = $g_cgival["tag"];
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();	// 拿到当前站点的site_id
	$admin_id = admin::admin_get_login_uid();	// 拿到当前管理员ID
	$admin_name = admin::admin_get_login_user_name();	// 拿到当前管理员用户名

	
	$db = new db_food_tag();
// 	$db->debug = true;
	
	

	$db->admin_delete_data($site_id, $tag, $tag_class, $admin_id, $admin_name);
	$admin_log = new admin_log();
	$admin_log->admin_insert_log_info($admin_id, $site_id, 1, "删除 标题为：{$tag} 分类为：{$tag_class} 的记录");
}




try
{
	admin_check_login();
	// 	admin_check_user_priv("foodv2/main_nav.php");

	check_cgi_pro();
	get_data();
	
	$g_show["error"] = 0;
	$g_show["errmsg"] = "成功";	
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;

	if (isset($_GET["debug"]))
	{
		echo "<pre>";
		print_r($g_show);
	}

	echo json_encode($g_show);
}